package com.example.coursedesign.ui.notifications.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.coursedesign.R;
import com.example.coursedesign.ui.notifications.entity.FamilyMember;

import java.util.List;

public class FamilyMemberAdapter extends RecyclerView.Adapter<FamilyMemberAdapter.FamilyMemberViewHolder> {

    private List<FamilyMember> familyMembers;
    private Context context;

    public FamilyMemberAdapter(Context context, List<FamilyMember> familyMembers) {
        this.context = context;
        this.familyMembers = familyMembers;
    }

    @NonNull
    @Override
    public FamilyMemberViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_add, parent, false);
        return new FamilyMemberViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FamilyMemberViewHolder holder, int position) {
        FamilyMember member = familyMembers.get(position);
        holder.bind(member);
    }

    @Override
    public int getItemCount() {
        return familyMembers.size();
    }

    public void setFamilyMembers(List<FamilyMember> familyMembers) {
        this.familyMembers = familyMembers;
        notifyDataSetChanged();
    }

    public static class FamilyMemberViewHolder extends RecyclerView.ViewHolder {

        private ImageView imageView;
        private TextView userName;
        private TextView relation;
        private TextView tel;

        public FamilyMemberViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            userName = itemView.findViewById(R.id.userName);
            relation = itemView.findViewById(R.id.relation);
            tel = itemView.findViewById(R.id.tel);
        }

        public void bind(FamilyMember member) {
            // Load the image using a library like Glide or Picasso if it's from a URL
            // For example: Glide.with(context).load(member.getAvatar()).into(imageView);
            userName.setText(member.getName());
            relation.setText(member.getRelation());
            tel.setText(member.getTel());
        }
    }
}